package com.team.ai.controller;

import com.team.ai.entity.ResultEntity;
import com.team.ai.service.VideoService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("v2/Video/")
public class VideoController {
    private static final Logger logger = LoggerFactory.getLogger(VideoController.class);//日志getLogger需要传入的类名

    @Resource
    VideoService videoService;

    @PostMapping("insert")
    private String insert(
            @RequestParam(value = "video",defaultValue = "-1") String video,
            @RequestParam(value = "title",defaultValue = "-1") String title
    ){
        return videoService.insert(video, title);

    }

    /**
     * 删
     * @param id
     * @return
     */
    @DeleteMapping("delete")
    private String delete(
            @RequestParam(value = "id",defaultValue = "-1") int id

    ){
        if (id==-1){
            return ResultEntity.fail(-10002);
        }
        return videoService.delete(id);
    }

    /**
     * 改
     */
    @PostMapping("update")
    private String update(
            @RequestParam(value = "video",defaultValue = "-1") String video,
            @RequestParam(value = "title",defaultValue = "-1") String title,
            @RequestParam(value = "id",defaultValue = "-1") int id
    ){
        if (id==-1){
            return ResultEntity.fail(-10002);
        }
        return videoService.update(video,title, id);

    }


    /**
     * 查
     * @return
     */
    @GetMapping("selectList")
    private String selectList(

    ){
        return videoService.selectList();

    }
    @GetMapping("selectDetail")
    private String selectDetail(
            @RequestParam(value = "id",defaultValue = "-1") int id

    ){
        return videoService.selectDetail(id);

    }

}
